﻿using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.IO;

namespace OpenLS.Spreadsheet.Formats.Biff.Records
{
    internal class FtPioGrbit
    {
        private bool _fAutoLoad;
        private bool _fAutoPict;
        private bool _fCamera;
        private bool _fCtl;
        private bool _fDde;
        private bool _fDefaultSize;
        private bool _fIcon;
        private bool _fPrintCalc;
        private bool _fPrstm;
        private bool _unused1;

        public void Read(BinaryReader reader)
        {
            ushort ft = reader.ReadUInt16();
            Contract.Assert(ft == 0x0008);
            ushort cb = reader.ReadUInt16();
            Contract.Assert(cb == 0x0002);
            ushort aj = reader.ReadUInt16();
            _fAutoPict = (aj & 0x01) != 0;
            _fDde = (aj & 0x02) != 0;
            _fPrintCalc = (aj & 0x04) != 0;
            _fIcon = (aj & 0x08) != 0;
            _fCtl = (aj & 0x010) != 0;
            _fPrstm = (aj & 0x020) != 0;
            _unused1 = (aj & 0x040) != 0;
            _fCamera = (aj & 0x080) != 0;
            _fDefaultSize = (aj & 0x0100) != 0;
            _fAutoLoad = (aj & 0x0200) != 0;
        }

        public void Write(BinaryWriter writer)
        {
            ushort ft = 0x0008;
            writer.Write(ft);
            ushort cb = 0x0002;
            writer.Write(cb);
            ushort aj = 0;
            if (_fAutoPict) aj |= 0x01;
            if (_fDde) aj |= 0x02;
            if (_fPrintCalc) aj |= 0x04;
            if (_fIcon) aj |= 0x08;
            if (_fCtl) aj |= 0x010;
            if (_fPrstm) aj |= 0x020;
            if (_unused1) aj |= 0x040;
            if (_fCamera) aj |= 0x080;
            if (_fDefaultSize) aj |= 0x0100;
            if (_fAutoLoad) aj |= 0x0200;
            writer.Write(aj);
        }
    }
}